package com.kanasco.vision.dao;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.kanasco.vision.model.Sales;

import bb.access.po.AccountsChart;
import bb.access.po.Currency;
import bb.access.po.CustomerVendorAddressInfo;
import bb.access.po.Incoterm;
import bb.access.po.Part;
import bb.access.po.PartType;
import bb.access.po.Project;
import bb.access.po.SalesCode;
import bb.access.po.SalesOrder;
import bb.access.po.Term;
import bb.access.po.Unit;
import bb.access.po.WeightUnit;
import bb.common.PartPK;


public class SalesImpl implements ISalesDao
{
	private HibernateTemplate hibernateTemp;


	public void setHibernateTemp(HibernateTemplate hibernateTemp) {
		this.hibernateTemp = hibernateTemp;
	}

	public boolean create(SalesOrder sales) {
		
		System.out.println("Now Iam in Create salesImpl");
		
		hibernateTemp.save(sales);
		return false;  
	}


	public List<String> getIncoTerm() {
		List<String> incoterm=new ArrayList();
        List<Incoterm>  inIds=new ArrayList<Incoterm>();
        inIds= hibernateTemp.find("from bb.access.po.Incoterm");
        for(Incoterm types:inIds)
        {
        	incoterm.add(types.getId());
        }
        System.out.println("size is"+incoterm.size());
      
        return  incoterm;
	}

	public List<String> getSalesCode() {
	List<String> scode=new ArrayList<String>();
	List<SalesCode> salesCode=hibernateTemp.find("from bb.access.po.SalesCode");
	for(SalesCode types:salesCode)
    {
    	scode.add(types.getSalesCodeId());
    	scode.add(types.getSalesCodeName());
    }
    System.out.println("size is"+scode.size());
  
    return  scode;

	}

	public List<String> getCurrency() {
		List<String> currency=new ArrayList<String>();
		List<Currency> curre=hibernateTemp.find("from bb.access.po.Currency");
		for(Currency types:curre)
	    {
			currency.add(types.getCurrency());
		
	    }
	    System.out.println("size is"+currency.size());
	  
	    return currency;
	}
	public boolean update(SalesOrder so) 
	{
	

		System.out.println("The sales number from sales Impl"+so.getSalesOrderNumber());
		System.out.println("The sales Requester from sales Impl"+so.getRequester());
		System.out.println("The sales Requester from sales Impl"+so.getLastUser());
		
		System.out.println("Now Iam in Create salesImpl");
		hibernateTemp.update(so);
		return false;  
	}


	public List<CustomerVendorAddressInfo> getCustList() 
	{
		System.out.println("In AccImpl getall");
	    List<String> list=new ArrayList();
	    List<CustomerVendorAddressInfo> custlist=new ArrayList<CustomerVendorAddressInfo>();
	
	   /*itemlist1= hibernatetemp.find("select pn,pa,rv,mn,commodity_code from bb.access.po.Part");*/
	    custlist= hibernateTemp.find("from bb.access.po.CustomerVendorAddressInfo");
	   for(CustomerVendorAddressInfo clist:custlist)
		{
		   
		    list.add(clist.getId());
		    list.add(clist.getName());
		    list.add(clist.getAddress());
		    
		    System.out.println("Customer Number is"+clist.getId());
		}
	   System.out.println("In AccImpl getall"+list.get(0));
		
		return custlist;
	}

	/*public boolean load(SalesOrder sales) 
	{
		System.out.println("Customer Id from Load is"+sales.getCustomerId());
		CustomerVendorAddressInfo info=(CustomerVendorAddressInfo) hibernateTemp.load(CustomerVendorAddressInfo.class, sales.getCustomerId());
		String id=info.getId().toString();
		System.out.println("The customer Id is"+id);
		return true;
	}*/

	public CustomerVendorAddressInfo load(String id)
	{
		CustomerVendorAddressInfo info= new CustomerVendorAddressInfo();
		
		
		
			System.out.println("Customervendor Addrs load");
		
			/*info= hibernateTemp.find("from bb.access.po.CustomerVendorAddressInfo where id=? ", id);*/
			hibernateTemp.load(info, id);
		
		
	
		
		return info;

	}

	public boolean Save(Term term) 
	{
    System.out.println("Now Iam in save Terms alesImpl");
	hibernateTemp.save(term);
	return false;
	}


	public List<Integer> getTermList() 
	{
		System.out.println("In AccImpl getall");
	    List<Integer> list=new ArrayList<Integer>();
	    List<Term> termlist=new ArrayList<Term>();
	    termlist= hibernateTemp.find("from bb.access.po.Term");
	    for(Term term:termlist)
	    {
	    list.add(term.getTerm());
	    }
	    
	    return list;
	}

	public List<String> getProjectList() 
	{
		List<String> prjList=new ArrayList<String>();
		List<Project> curre=hibernateTemp.find("from bb.access.po.Project");
		for(Project types:curre)
	    {
			prjList.add(types.getId());
		
	    }
	    System.out.println("Project list size is"+prjList.size());
	  
	    return prjList;
	}

	public List<String> getAcctList() 
	{
		List<String> acctList=new ArrayList<String>();
		List<AccountsChart> chart=hibernateTemp.find("from bb.access.po.AccountsChart");
		for(AccountsChart types:chart)
	    {
			acctList.add(types.getAccountNumber());
		
	    }
	    System.out.println("Project list size is"+acctList.size());
	  
	    return acctList;
	}


	public List<String> getItemType()
	{
			List<String> item_type=new ArrayList();
	        List<PartType>  itemTypes=new ArrayList<PartType>();
	        itemTypes= hibernateTemp.find("from bb.access.po.PartType");
	        for(PartType types:itemTypes)
	        {
	    	  item_type.add(types.getPartType());
	        }
	        System.out.println("size is"+item_type.size());
	      
	        return  item_type;
	
   }
	public List<String> getItemUOM() 
	{
		  List<String> item_uom=new ArrayList();
		  List<Unit>  itemuoms=new ArrayList<Unit>();
		 itemuoms= hibernateTemp.find("from bb.access.po.Unit");
		 for(Unit unit:itemuoms)
		 {
			 item_uom.add(unit.getUnitName());
		 }
		 return item_uom;
	}


	public List<String> getCustInfo(String id) 
	{
		List<String> list=new ArrayList<String>();
		List<CustomerVendorAddressInfo> cust=new ArrayList<CustomerVendorAddressInfo>();
		cust=hibernateTemp.find("from bb.access.po.CustomerVendorAddressInfo where id=? ", id);
		for(CustomerVendorAddressInfo info:cust)
		{
			list.add(info.getId());
			list.add(info.getName());
			System.out.println("Customer name"+list.get(1));
			list.add(info.getAddress());
			list.add(info.getAddress2());
			list.add(info.getCity());
			list.add(info.getLastUser());
		}
		return list;
	}

	

	

	
	}

